package com.pure.common.composite.impl;

import com.pure.common.composite.Counter;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 容器
 * @date: 2022-05-28 15:48
 * @since 1.2.0
 **/
@Slf4j
public class Container implements Counter {

    private List<Counter> containerList = new ArrayList<>();

    /**
     * @description: 添加
     * @date 2022/5/28 3:52 下午
     * @since 1.2.1
     */
    public void add(Counter counter) {
        containerList.add(counter);
    }

    /**
     * @description: 删除
     * @date 2022/5/28 3:53 下午
     * @since 1.2.1
     */
    public void del(Counter counter) {
        containerList.remove(counter);
    }

    @Override
    public int count() {

        int sum = 0;

        for (Counter counter : containerList) {
            sum += counter.count();
            log.info("当前人口统计数量 {}", sum);
        }

        return sum;
    }

}
